package it.uitest;

import com.dirox.confluence.labelmanagement.utils.MailHelper;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.openqa.selenium.WebDriver;


public class SendMailRule extends TestWatcher {
	public WebDriver browser;

	public SendMailRule(WebDriver browser) {
		this.browser = browser;
	}

	@Override
	public void failed(Throwable e, Description description) {
		MailHelper.sendFromGmail("phuocndv@dirox.net",
			"Test Failed: " + description.getMethodName(),
			"Description: " + description.getDisplayName() + "\nFail: "
			+ e.getMessage());
	}

	@Override
	public void succeeded(Description description) {}

	@Override
	public void finished(Description description) {
		if (browser != null) {
			browser.quit();
		}
	}
}
